<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>ES6 DEMO</title>
</head>
<body>

<button type="button" onclick="syas()">says</button>

<script>
	//参考 https://segmentfault.com/a/1190000004365693
	//exprot的用法 这个比较重要
	//https://segmentfault.com/a/1190000004368132

	//类
	class Animal {
		constructor(){
			this.type = 'animal'
		}
		says(say){
			console.log(this.type + ' says ' + say)
		}
	}
	// let animal = new Animal()
	// animal.says('hello') //animal says hello
	class Cat extends Animal {
	    constructor(){
	        super() //子类必须在constructor方法中调用super方法，否则新建实例时会报错。这是因为子类没有自己的this对象，而是继承父类的this对象
	        this.type = 'rabbit'
	    }
	}
	let rabbit = new Cat()
	const syas=()=>{
		rabbit.says('hello') //cat says hello
	}

	let cat = 'ken'
	let dog = 'lili'
	let zoo = {cat, dog}
	console.log(zoo)  //Object {cat: "ken", dog: "lili"}

	let duck = {type: 'animal', many: 2, name:'cj'}
	let { type, many, name } = duck
	console.log(type);
	console.log(many);
	console.log(name);

	//给函数设定默认值
	function animal2(type = 'cat'){
	    console.log(type)
	}
	animal2('dog')

	//rest
	function animals(...types){
	    console.log(types)
	}
	animals('cat', 'dog', 'fish') //["cat", "dog", "fish"]
</script>
	
</body>
</html>